package com.erp.erp_servers.Email;

import com.erp.erp_entitys.Email.*;
import com.erp.erp_entitys.User.UserEntity;
import com.erp.erp_entitys.warehouse.entity.AnnexEntity;
import com.erp.erp_servers.Dictionary.IDictionary2Service;
import com.erp.erp_servers.Ftp.IFtpService;
import com.erp.utils.R;

import javax.mail.MessagingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public interface EmailService {
    //将读取协议信息从数据库拉取出来
    List<email_Pop3> selectAllEmail_Pop3();
    List<email_Pop3> selectAllEmail_Pop3byUserCode(String code);
    //根据pop3id获取全部邮件并根据时间排序
    List<email_email> selectAllEmailBypop3IDS(emailOrder order);
    void updateEmail_Pop3(int pop3_id, String uid);
    int addEmail_email(email_email email);
    void insertEmail_adjunct(email_adjunct email_adjunct);
    List<email_adjunct> selectAdjunctForEmail_ID(int email_id);
    email_adjunct selectAdjunctForAdjunct_ID(int adjunct_id);
    email_email selectEmailByEmail_id(int email_id);
    email_Pop3 selectPOP3Bypop3_id(int pop3_id);
    void updateEmail_emailReady1(int email_id);
    void updateEmail_emailReady2(int email_id);
    void updateUpAdjunct(email_adjunct adjunct);
    List<email_adjunct> selectAllAdjunct();
    List<email_email> selectAllEmailbyPOP3_id(int pop3_id);
    //新建箱子
    int insertBox(email_box box);
    //箱子加入邮件
    void insertBox_Email(email_box_emailid emailid);
    //查询箱子所有邮件
    List<email_email> selectEmailForBoxID(int boxID);
    //查询用户的查询箱子id
    email_box selectSearchBox(String code);
    //根据邮件id批量查询邮件
    List<email_email> selectEmailForEmailID(List<Integer> emailIDs);
    //删除箱子
    void deleteBox(int boxID);
    //删除箱子内邮件
    void deleteBox_email(int boxID);
    //查询所有的箱子
    List<email_box> selectAllBox(String code);
    //新建规则
    int insertSearch(searchEmail searchEmail);
    //删除规则
    void deleteSearch(int searchID);
    //查询规则
    searchEmail selectSearch(int searchID);
    //新增pop3
    void insertPop3(email_Pop3 pop3);
    void updatePop3(email_Pop3 pop3);
    void deletePop3(int pop3id);
    //stmp增删改查
    void insetStmp(email_smtp smtp);
    void updateStmp(email_smtp smtp);
    void deleteStmp(int smtoID);
    List<email_smtp> selectStmp(String code);
    email_smtp selectStmpById(int stmpid);
    void insertEmail_mass(email_mass mass);
    void insertTag(int emailID, String tag);
    void deleteTag(int emailID);
    void insertStar(int emailID);
    void deleteStar(int emailID);
    List<email_email> selectAllEmailbyPOP3_idNoReady(int pop3_id);
    List<email_email> selectAllEmailNoReady();
    List<email_email> searchEmail(searchEmail searchEmail);
    void changeXinbiao0(Integer emailID);
    void changeXinbiao1(Integer emailID);
    void changeTag(Tag tt);
    List<email_email> selectApproveEmailByCode(String code);
    List<email_email> selectEmailByGaoji(searchEmail search);
    email_box selectBoxById(Integer box_id);
    void updateSearch(searchEmail search);
    void updateBox(email_box box);
    void updateEmailClass(changeEmailClass chage);
    void changeEmailReady(changeEmailReady chage);
    void changeAllEmailReady(List<email_Pop3> pop3s);
    List<email_email> selectEmailByAnswer(List<email_Pop3> pop3s);
    List<email_email> selectEmailByready(List<email_Pop3> pop3s);
    void updateReadStatue(Integer emailID);
    int insertEmail_account(email_account account);
    void deleteEmail_account(email_account account);
    List<email_account> selectEmail_accountBycode(String code);
    void updateEmail_account(email_account account);
    email_account selectEmail_accountById(Integer ccid);
    void updateEmail_accountStatues();
    void insertTemplate(email_template template);
    void deleteTemplate(email_template template);
    void updateTemplate(email_template template);
    List<email_template> selectTemplates(String code);
    void updateTemplateNodefault(String code);
    email_template selectTemplateByid(Integer template_id);
    void inserteDeploy(email_deploy deploy);
    email_deploy selectDeploy(String Code);
    void updateDeploy(email_deploy deploy);
    List<email_email> selectdraft(String code);
    //判断箱子里是否有该邮件
    List<email_box_emailid> selectEmailForBoxIsExist(Integer boxid, Integer emailid);
    //判断所有箱子里是否有该邮件
    List<email_box_emailid> selectAllEmailForBoxIsExist(Integer emailid);
    //收信规则设置
    void insertEmailRules(EmailRules rule);
    List<EmailRules> selectEmailRulesBycode(String code);
    EmailRules selectEmailRulesByID(Integer id);
    void updateEmailRules(EmailRules rule);
    void deleteEmailRules(Integer id);
    Integer selectNowEmail(email_nowEmail ne);
    email_email selectnotFind(String emailAddress);
    Map<String,Integer> notFind(List<String> address);
    /**
     * 30天、60天未联系的客户
     * @return
     */
    Map<String,Object> getCountContact(UserEntity user);
    List<email_Pop3> selectAllEmail_Pop3NotStatue();
    //下载所有邮件元数据
    int upDateEmail();
    //下载邮件附件
    void upLoadAdjunctMore(IDictionary2Service dictionary2Service, IFtpService iFtpService) throws Exception;
    //根据pop3下载邮件元数据定时器
    void getAllemailAuto(email_Pop3 pop) throws MessagingException;
    //根据pop3下载邮件元数据定时器
    void  getAllemail(email_Pop3 pop) throws MessagingException;
    //判断邮件是否存在重复
    email_email selectReuse(email_email email);
    //下载单个邮件附件
    R<String> upLoadAdjunctOne(Integer emailID) throws Exception;
    //发送邮件
    R<String> sendEmailNow(email_message message);
    //存储定时邮件
    void insetSendMessage(send_message send_message);
    //获取定时邮件
    List<send_message> selectSendMessage();
    //删除定时邮件
    void deleteSend_message(int id);
    //测试pop是否可用
    String popLink(email_Pop3 pop3, UserEntity user);
    String popTest(email_Pop3 pop3);
    //测试imap是否可
   String smtpLink(email_smtp smtp,UserEntity user);
    Integer selectNoRead(List<email_Pop3> pop3s);
    void sendEmailTiming() throws Exception;
    //还原归并箱中邮件
    void ReturnEmailByBoxId(List<email_email> emails);
    void ReturnEmailByBoxId1(List<email_email> emails);
    void deleteMuchEmail();
    void deleteEmailInBox(int email_id);
    //当用户的邮箱进行维护后，需要先删除所有原有的内部联系人箱，入参为修改前的用户邮箱
    void deleteUserBox(String address);

    //查询各个箱体的总数和未读数
    List<emailReadNum> selectEmailReadNum(List<Integer> pop3s);
    //针对全体箱子进行查询
    email_box selectUserBoxByTwoCode(String code, String code1);
    //针对客户箱进行查询
    email_box selectUserBoxByTwoCode(String code);
    //针对客户箱进行查询(修改批量)
    List<email_box> selectUserBoxByTwoCode1(String code);
    /*检查所有的联系人对应到的联系人箱，更换规则
    * userClass  用户的类型  0 是用户 1是客户
    * type       操作类型（0新增，1修改，2删除）
    * oldemail   邮箱地址旧值
    * newEmail   邮箱地址新值
    * code       用户编码或客户联系人ID
    * name       用户或客户联系人名
    * */
    boolean checkUserBox(List<email_custor> email_custors);

    //初始化客户箱
    void custorsIV();
    //检查所有的客户联系人，新增则新增，删除则删除，修改则修改
    void checkCustor();

    email_box  selectSearchBySendAddress(String senderAddresser);

    void setEmailSize(int id, int size);

    void deleteAuto(emailAuto emailAuto);

    List<email_email> selectEmeilBySuject();

    void updateSubject(int email_id, String strr);

   /*新增规则及箱子
   * search:邮箱
   * name:客户名
   * box_creat_user：客户编码
   * */
    void addEmailBoxAndSearch(String search,String name,String box_creat_user);

    List<AnnexEntity> selectAllFileNmae();

    //存草稿或存已发
    String saveEmail(email_message message,UserEntity user,int email_class);

    List<email_email> selectCustorShowEmailByPage(ArrayList<String> emails);

    Integer checkEmailMore(email_email email);

    void deleteContext(Integer emailID);

    /**
     * 根据条件查询邮件
     * @param email
     * @return
     */
    List<email_email> selectEmailByParam(email_email email);

    String SearchTerm(Integer pop3_id, Date startTime, Date endTime, Integer high,Integer type);
}

